<html>
  <head>
    <!--Load the AJAX API-->
    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">
    
      // Load the Visualization API and the bar chart package.
      google.load("visualization", "1", {packages:['gauge']});
      
      // Set a callback to run when the Google Visualization API is loaded.
      google.setOnLoadCallback(initializeData);

      // Once visualization API is loaded, retrieve data and set callbacks to run once retrieved.
      function initializeData() {
        // Get all of the dorm data from the spreadsheet.
        var dormDataURL = 'http://spreadsheets.google.com/tq?key=0Av0U6TKHfzXYdG1vUnduR0RVTktyR1ZtNjAtSE9Qbmc&range=A3:F21&gid=0';
        var dormDataQuery = new google.visualization.Query(dormDataURL);
        // Update the gauges every 5 seconds
        dormDataQuery.setRefreshInterval(5);
 
        // Set a callback to run when the dorm data has been retrieved.
        dormDataQuery.send(displayDormData);
      }

      
      // Callback that gets the dorm data and creates DataViews to display each table individually.
      function displayDormData(response) {
        // Process errors, if any.
        if (response.isError()) {
            alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
            return;
        }
        
        // Get the dorm data table.
        var data = response.getDataTable();
        
        // Create the view that is just ilima floors.
        var view = new google.visualization.DataView(data);
        view.setColumns([1,2]);
        view.setRows(0, 4);
        var chart = new google.visualization.Gauge(document.getElementById('chart_div'));
        chart.draw(view, {height: 100, max: 1000, greenFrom: 0, greenTo: 500, yellowFrom:501, yellowTo: 750, redFrom: 751, redTo: 1000});
      }

    </script>
  </head>

  <body>
    <h3>Ilima Individual Floor Power Gauges</h3>
    <div id="chart_div"><img src="http://www.google.com/ig/images/spinner.gif"/></div>
  </body>
</html>

